*********************************************************
*About the Stata syntaxes:
*The do files contain Stata syntaxes. Datasets containing information on student borrowers are available only through restricted-use license from the United States Department of Education. 
*Contents of licensed files – such as variable statistics, variable descriptions, and numbers of observations – are protected by Section 183 of the Educational Sciences Reform Act of 2002. 
*Therefore, syntaxes related to variable names are redacted to a generic form. 

*Please see the "README" file for how to apply for the licensed data.
**********************************************************

*** The following are for Table 2 and Figure 1
clear
use File2

include Controls

foreach var in 0.1 0.15{
replace prop=`var'

forvalues i=1(1)5{
replace pov_line=pov`i'

gen hypo_studentr=((sal17-1.5*pov_line)*prop)/12

by student: egen distr_total=total(distr)
replace hypo_studentr=hypo_studentr*(distr/distr_total)
replace hypo_studentr=0 if hypo_studentr<5 // according to IES, if scheduled studentR payment <5, then required payment=0 

* Calculate hypothetical sal
gen hypo_sal17=((hypo_standard/(distr/distr_total))*12)/prop+1.5*pov_line

* Generate log
gen ln_hypo_studentr=ln(1+hypo_studentr)
gen ln_hypo_sal17=ln(1+hypo_sal17)

preserve
keep if switch==0

* Generate data points for figures
reg hypo_standard [pw=$weight]

reg hypo_studentr [pw=$weight]

reg sal17 [pw=$weight]

reg hypo_sal17 [pw=$weight]
restore

local var100=`var'*100
gen sal17_growth=sal17*(1+a_median_g_mean)^3

gen flag`var100'`i'=1 if sal17_growth>=hypo_sal17 & sal17!=.

drop hypo_studentr ln_hypo_studentr distr_total hypo_sal17 ln_hypo_sal17 sal17_growth 
}
}

preserve
keep if switch==0

gen obs=_N

foreach var in 10 15{
forvalues i=1(1)5{
egen obs`var'`i'=total(flag`var'`i')
replace obs`var'`i'=obs`var'`i'/obs
reg obs`var'`i'
}
}
restore


clear
use File3

include Controls

foreach var in 10 15{
forvalues i=1(1)5{
preserve
drop if switch==0 & flag`var'`i'==1
drop if switch==1 & continueIBR_id==1 & pay_type!="REPAYE" & flag`var'`i'==1 // pay_type value is redacted

ivreg2 switch $control6 [pw=$weight], cluster($cluster)

restore
}
}
 
